/**
 * @author dss
 */
_dss_editor._urlplayer.playingUrl = '';

_dss_editor._urlplayer.play = function(url, canvas) {
    var fileType = url.substr(url.lastIndexOf('.') + 1);
    if (fileType === 'mp3') {
        this.playAudio(url, canvas);
    } else if (fileType === 'pdf') {
        this.playDoc(url);
    } else if (fileType === 'jpg' || fileType === 'png') {
        this.playImage(url);
    }
    this.playingUrl = url;
};
_dss_editor._urlplayer.playAudio = function(url, canvas) {
    //url = this.createUrl(url);
    this.closeAudioPlayer(canvas);
    var player = $C('audio');
    var panel = $C('div');
    var closeImg = $C('img');
    var parentNode = canvas.entity.parentNode;
    player.src = url;
    player.autoplay = true;
    player.controls = "controls";
    closeImg.src = 'themes/icons/cancel.png';
    closeImg.onmousemove = function() {
        this.style.cursor = 'pointer';
    };
    closeImg.onclick = function() {
        _dss_editor._urlplayer.close(canvas);
    };
    panel.id = 'urlPlayer';
    panel.appendChild(player);
    panel.appendChild(closeImg);
    panel.setAttribute("style", "top:" + (parentNode.offsetHeight) + "px;left:" + parentNode.offsetX + "px;position:fixed;font-size: 16px;");
    parentNode.appendChild(panel);
};
_dss_editor._urlplayer.playDoc = function(url) {
    // url = this.createUrl(url);
    $('#canvasTabs').tabs('add', {
        title : url.substring(url.lastIndexOf('/') + 1, url.length),
        content : '<embed src="' + url + '" width="100%" height="100%"></embed>',
        closable : true
    });
};
_dss_editor._urlplayer.playImage = function(url) {
    //url = this.createUrl(url);
    $('#canvasTabs').tabs('add', {
        title : url.substring(url.lastIndexOf('/') + 1, url.length),
        content : '<div width="100%" height="100%"><img src="' + url + '"></img></div>',
        closable : true
    });
};
_dss_editor._urlplayer.playJson = function(name,content) {
    if (content) {
        var sysForView = JSON.parse(content);
        var canvas = _dss_editor._canvas._operation.buildTab(name, _dss_editor._canvas._type.VIEW);
        canvas.init(sysForView);
        canvas.matchSize();
        canvas.update();
    }
};
_dss_editor._urlplayer.close = function(canvas) {
    if (this.playingUrl === '') {
        return;
    }
    var fileType = this.playingUrl.substr(this.playingUrl.lastIndexOf('.') + 1);
    if (fileType === 'mp3') {
        this.closeAudioPlayer(canvas);
    } else if (fileType === 'pdf') {
        this.closeDocPlayer();
    }
};
_dss_editor._urlplayer.closeAudioPlayer = function(canvas) {
    var parentNode = canvas.entity.parentNode;
    var player = $('#urlPlayer')[0];
    if (player) {
        parentNode.removeChild(player);
    }
};
_dss_editor._urlplayer.closeDocPlayer = function() {
    $('#canvasTabs').tabs('close', this.playingUrl);
};
_dss_editor._urlplayer.createUrl = function(url) {
    url = url.substring(url.indexOf(':') + 1, url.length);
    url = jQuery.trim(url);
    url = 'file/' + url;
    return url;
};

